﻿using System;
using System.Xml;
using Algorithm;
using Engine;
using Configuration;
using System.Windows.Forms;
using EventBroker;
using System.Threading;
using ThreadPool;

namespace CentralizedControlHub
{
    /// <summary>
    /// This class controls the start of the jumper
    /// </summary>
    public class CJumperLauncher
    {
        
        public CAlgorithmSetup m_algorithmSetup;
        public CJumperEngine m_jumperEngine;
        public SmartThreadPool m_threadPool;

        /// <summary>
        /// Constructor
        /// </summary>
		public CJumperLauncher()
		{			
            m_algorithmSetup = new CAlgorithmSetup("WebPages.xml");
            m_jumperEngine = new CJumperEngine(m_algorithmSetup.WebPageConcreteFactories);
            CEventManager.Register(m_jumperEngine);
            m_threadPool = SmartThreadPool.GetInstance();
		}

        /// <summary>
        /// Start the Engine which in turn starting all the jumpers
        /// </summary>
        public void Start()
        {
            m_jumperEngine.Start();
            System.Diagnostics.Debug.WriteLine("Wait for ThreadPool to be idle");
            m_threadPool.WaitForIdle();
            System.Diagnostics.Debug.WriteLine("ThreadPool is idle");
            MessageBox.Show("End");
            
        }

    }
}
